package com.xcesys.extras.remoting;

import java.util.Collection;
import java.util.List;

import com.xcesys.extras.dataobject.AbstractDataObject;
import com.xcesys.extras.dataobject.PaginationContent;
import com.xcesys.extras.dataobject.QueryObject;

/**
 * Remoting crud service interface.
 * 
 * @author danne
 * 
 * @param <T>
 *            a subclass of {@link AbstractDataObject}
 */
public interface RemotingCrudService<T extends AbstractDataObject> extends
		RemotingService {

	/**
	 * Creates a model from data.
	 * 
	 * @param d
	 *            data submit.
	 * @return data object created.
	 */
	T create(T d);

	/**
	 * @param list
	 * @return
	 */
	Collection<T> createOrUpdate(Collection<T> list);

	/**
	 * Deletes data according to id.
	 * 
	 * @param id
	 */
	void delete(Long id);

	/**
	 * Deletes an array of objects by given identifiers.
	 * 
	 * @param ids
	 *            a list of identifiers.
	 */
	void deleteByIds(List<Long> ids);

	/**
	 * Returns a list of data object from all model.
	 * 
	 * @return
	 */
	List<T> findAll();

	/**
	 * @param query
	 * @return
	 */
	PaginationContent<T> findByCriteria(QueryObject query);

	/**
	 * Returns data from model with given identifier, exception if data does not
	 * existed.
	 * 
	 * @param id
	 * @return data with given id.
	 */
	T findById(Long id);

	/**
	 * Returns a list of data object from model with given array of identifiers.
	 * 
	 * @param ids
	 * @return
	 */
	List<T> findByIds(Long[] ids);

	/**
	 * Returns data from model with given identifier, null returned if data does
	 * not existed.
	 * 
	 * @param id
	 * @return data with given id.
	 */
	T getById(Long id);

	/**
	 * Updates data to model.
	 * 
	 * @param d
	 * @return
	 */
	T update(T d);
}
